package com.itheima.controller;

import com.itheima.entity.Comment;
import com.itheima.entity.Movies;
import com.itheima.result.Result;
import com.itheima.service.CommentService;
import com.itheima.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("single")
public class SingleController {

    @Autowired
    private MovieService movieService;

    @Autowired
    private CommentService commentService;

    @GetMapping("findMovieById")
    public Result findMovieById(@RequestParam Integer id){
        //调用service根据id查询影视
        Movies movies = movieService.findById(id);
        return Result.success(movies);
    }

    @GetMapping("findMovieCommentListByMovieId")
    public Result findMovieCommentListByMovieId(@RequestParam Integer id){
        //调用service根据影视id查询评论列表
        List<Comment> list = commentService.findListByMovieId(id);
        return Result.success(list);
    }

    @PostMapping("saveComment")
    public Result save(@RequestBody Comment comment){
        commentService.save(comment);
        return Result.success();
    }
}
